<?
require("includes/constants.php");
require("includes/funciones.inc.php");

session_start();
if(!isset($_SESSION['userName']))
	exit();

$DB = NewADOConnection('mysqlt');
$DB->Connect();
$DB->Execute("SET NAMES utf8;");
//$DB->debug=true;

$sSQL = "SELECT cp.*, c.tipoCarrera FROM carrera_ptos cp
			INNER JOIN carreras c ON cp.idCarrera = c.idCarrera
				WHERE c.idCarrera = ".$_REQUEST['idCarrera'];
$rsCarrera = $DB->Execute($sSQL);

$ptos = array();
$keysPto = array();
while (!$rsCarrera->EOF) {
	$objPto = "";
	$objPto->idPto = $rsCarrera->fields('idPto');
	if($rsCarrera->fields('tipoCarrera') == $tipoCarreraUnaPta) {
		$objPto->descPto = $rsCarrera->fields('descriptionPto');
	}
	else {
		switch ($rsCarrera->fields('idPto')) {
			case  $idNorte:
				$objPto->descPto = "NORTE - ".$rsCarrera->fields('descriptionPto');
				break;
			case  $idSur:
				$objPto->descPto = "SUR - ".$rsCarrera->fields('descriptionPto');
				break;
			case  $idEste:
				$objPto->descPto = "ESTE - ".$rsCarrera->fields('descriptionPto');
				break;
			case  $idOeste:
				$objPto->descPto = "OESTE - ".$rsCarrera->fields('descriptionPto');
				break;
		}
	}
	
	array_push($ptos, $objPto);
	array_push($keysPto, $rsCarrera->fields('idPto'));
	$rsCarrera->MoveNext();
}
?>

<div id="mainPopUp">
	<button id="btnCloseTablasPop" class="itmIngBtnIn">Cerrar</button>
	<?php if($_SESSION['userType'] != $idTypeDataEntry) { ?>
		<button id="btnImportTablasPop" class="itmIngBtnIn">Importar Datos</button>
		<button id="btnRecalcularPop" class="itmIngBtnIn">Recalcular Datos</button>
	<?php }?>
	<button id="btnAddItemPop" class="itmIngBtnIn">Ingresar</button>

	<!-- PopUp Team Dialog -->
	<div id="carrerasDialogItem"></div>
	
	<!-- PopUp FileUpload Carreras Dialog -->
	<div id="uploadCarrerasDialog" style="display: none;">
		<table>
			<tr>
			<td>Punto Cardinal</td>
				<td>
					<select id="carreraImportPtoCardinal" class="tableIn">
					<?php foreach ($ptos as $objPto) {?>
						<option value="<?php echo $objPto->idPto?>"><?php echo $objPto->descPto?></option>
					<?php }?>
					</select>
				</td>
			</tr>
		</table>
		<div id="fileUpload"></div>
	</div>
</div>

<!-- Tablas NORTE, SUR, ESTE, OESTE para ver los resultados -->
<?php if (in_array($idNorte, $keysPto)) {?>
<br />
<p class="textPopHeaderTable">Norte</p>
<button id="btnDeleteNorteItemPop" class="itmIngBtnIn">Eliminar</button>
<button id="btnEditNorteItemPop" class="itmIngBtnIn">Editar</button>
<table id="dt_carrerasNorte" class="display">
	<thead>
		<tr>
			<th>Id</th>
			<th>Usuario</th>
			<th>Tipo</th>
			<th>Paloma</th>
			<th>D&iacute;a Marca</th>
			<th>Hora Marca</th>
			<th>Adelanto</th>
			<th>Atraso</th>
			<th>Puntos</th>
			<th>Puesto</th>
			<th>Especial</th>
			<th>Metros x Min.</th>
			<th>Distancia Palomar</th>
			<th>Min. Recorridos</th>
		</tr>
    </thead>
    <tbody>
    	<tr>
    		<td colspan="14" class="dataTables_empty">Cargando Datos...</td>
    	</tr>
	</tbody>
</table>
<!-- PopUp Delete Items Dialog -->
<div id="deleteItemsNorteDialog" style="display: none;">
	<div id="tituloPopUp">Realmente desea eliminar este registro?</div>	
	<button class="itmIngBtn" id="btnConfirmNorteDelete">S&iacute;</button>
	<button class="itmIngBtn" id="btnExitNorteDelete">No</button>		
</div>
<?php }?>

<?php if (in_array($idSur, $keysPto)) {?>
<br />
<p class="textPopHeaderTable">Sur</p>
<button id="btnDeleteSurItemPop" class="itmIngBtnIn">Eliminar</button>
<button id="btnEditSurItemPop" class="itmIngBtnIn">Editar</button>
<table id="dt_carrerasSur" class="display">
	<thead>
		<tr>
			<th>Id</th>
			<th>Usuario</th>
			<th>Tipo</th>
			<th>Paloma</th>
			<th>D&iacute;a Marca</th>
			<th>Hora Marca</th>
			<th>Adelanto</th>
			<th>Atraso</th>
			<th>Puntos</th>
			<th>Puesto</th>
			<th>Especial</th>
			<th>Metros x Min.</th>
			<th>Distancia Palomar</th>
			<th>Min. Recorridos</th>
		</tr>
    </thead>
    <tbody>
    	<tr>
    		<td colspan="14" class="dataTables_empty">Cargando Datos...</td>
    	</tr>
	</tbody>
</table>
<!-- PopUp Delete Items Dialog -->
<div id="deleteItemsSurDialog" style="display: none;">
	<div id="tituloPopUp">Realmente desea eliminar este registro?</div>	
	<button class="itmIngBtn" id="btnConfirmSurDelete">S&iacute;</button>
	<button class="itmIngBtn" id="btnExitSurDelete">No</button>		
</div>
<?php }?>

<?php if (in_array($idEste, $keysPto)) {?>
<br />
<p class="textPopHeaderTable">Este</p>
<button id="btnDeleteEsteItemPop" class="itmIngBtnIn">Eliminar</button>
<button id="btnEditEsteItemPop" class="itmIngBtnIn">Editar</button>
<table id="dt_carrerasEste" class="display">
	<thead>
		<tr>
			<th>Id</th>
			<th>Usuario</th>
			<th>Tipo</th>
			<th>Paloma</th>
			<th>D&iacute;a Marca</th>
			<th>Hora Marca</th>
			<th>Adelanto</th>
			<th>Atraso</th>
			<th>Puntos</th>
			<th>Puesto</th>
			<th>Especial</th>
			<th>Metros x Min.</th>
			<th>Distancia Palomar</th>
			<th>Min. Recorridos</th>		
		</tr>
    </thead>
    <tbody>
    	<tr>
    		<td colspan="14" class="dataTables_empty">Cargando Datos...</td>
    	</tr>
	</tbody>
</table>
<!-- PopUp Delete Items Dialog -->
<div id="deleteItemsEsteDialog" style="display: none;">
	<div id="tituloPopUp">Realmente desea eliminar este registro?</div>	
	<button class="itmIngBtn" id="btnConfirmEsteDelete">S&iacute;</button>
	<button class="itmIngBtn" id="btnExitEsteDelete">No</button>		
</div>
<?php }?>

<?php if (in_array($idOeste, $keysPto)) {?>
<br />
<p class="textPopHeaderTable">Oeste</p>
<button id="btnDeleteOesteItemPop" class="itmIngBtnIn">Eliminar</button>
<button id="btnEditOesteItemPop" class="itmIngBtnIn">Editar</button>
<table id="dt_carrerasOeste" class="display">
	<thead>
		<tr>
			<th>Id</th>
			<th>Usuario</th>
			<th>Tipo</th>
			<th>Paloma</th>
			<th>D&iacute;a Marca</th>
			<th>Hora Marca</th>
			<th>Adelanto</th>
			<th>Atraso</th>
			<th>Puntos</th>
			<th>Puesto</th>
			<th>Especial</th>
			<th>Metros x Min.</th>
			<th>Distancia Palomar</th>
			<th>Min. Recorridos</th>
		</tr>
    </thead>
    <tbody>
    	<tr>
    		<td colspan="14" class="dataTables_empty">Cargando Datos...</td>
    	</tr>
	</tbody>
</table>
<!-- PopUp Delete Items Dialog -->
<div id="deleteItemsOesteDialog" style="display: none;">
	<div id="tituloPopUp">Realmente desea eliminar este registro?</div>	
	<button class="itmIngBtn" id="btnConfirmOesteDelete">S&iacute;</button>
	<button class="itmIngBtn" id="btnExitOesteDelete">No</button>		
</div>
<?php }?>

<script>
	$(document).ready(function() {
		$_initPopTablas();
	});
</script>